package math;

public class NumericLogicalVariable extends LogicalArithmeticVariable {

  public NumericLogicalVariable(String name) {
    super(name);
  }

  public NumericConstant getValue() {
    return (NumericConstant) super.getValue();
  }

  public void bind(NumericConstant value) {
    super.bind(value);
  }
  
  @Override
  public void bind(ArithmeticExpression value) {
    if (!(value instanceof NumericConstant))
      throw new IllegalArgumentException("Value must be a NumericConstant but is " + value.getClass());
    super.bind(value);
  }

  @Override
  public ArithmeticExpression derivate(Variable var) {
    throw new RuntimeException("NumericLogicalVariables can not be derivated");
  }


  @Override
  public boolean matches(Expression expr) {
    if (isBound()) {
      return getValue().matches(expr);
    } else {
      if (expr instanceof NumericConstant) {
        bind((NumericConstant) expr);
        return true;
      } else
        return false;
    }
  }

  @Override
  public String toString() {
    return "{@" + getName() + "}=" + getValue();
  }

  @Override
  public <R> R accept(ExpressionVisitor<R> visitor) {
    return visitor.visitNumericalLogicalVariable(this);
  }
}